package com.atguigu.gmall;

import com.alibaba.fastjson.JSONObject;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayTradePagePayRequest;
import com.alipay.api.response.AlipayTradePagePayResponse;

/**
 * @author 李旭
 * @date 2022/1/23 11:00
 * @Description:
 */
public class AlipayDemo {


    public static void main(String[] args) throws Exception{
        //1:支付宝的客户端
        AlipayClient alipayClient =  //沙箱版
                new DefaultAlipayClient(
                        "https://openapi.alipaydev.com/gateway.do",
                        "2016102100732915",
                        "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDcDMGGfsLI9fg8hkODHiUKxPyAfyTAdZ0DfqbXQIrCrtndyF36bBxEEF9KNjBSE8B/nP1as4vB4f46o3GEX1cFm5uBrIBh7m2pGr71N0iYWoEqEby5A28fy+V9RXkTZnJQBAzBh7cZlMtKMvfqRkDEMsTAuhOvVv9ciC5qvEkGMh8HO7TOJnH87+WsxdcSuCbchGFAOSUVW54F6b9hFSNljs51PfQdHVMd+PNZcxz266k6xGEjKVIlOXykV/U/MAb10dBpIMog90DyeleYDRcmbZK6GLz5/F+3yZXgoKjbMb2kPj1CFrWbF6sg0ngwYGYRKJ+80CMrTlpIZFCDzH/7AgMBAAECggEAdFGd3w2Uw4waG0xR1baSmB3G59nNwJqrVBSX9wLcFss8yVrIKr8JNgV9iYoZgtmEETEYT+DHCMcAj1ikgfev1XwK+MIJ3zqc5x4HQTJnAnoc+vMDUr14+VLbzZtyxAmMdbWeVJL7+97Gk0Nb/5ABXnUDwmjaTP5s4Cnwd2VuKIJM9JyJikGSOVqxRuILAhk6hbQSJbdWrlOvfSF+ilBjVnV03bD/wAeYxnSM1ZHo0ot7S2/G7roIe4UuDtp3Xg8e7U9iG6feTWBcI0KZmDUGFXk6W7NzX7nVzS7MstfPnP8LE30vlvywEdlG20cIpmhPfrkim/ZQQB3IkgAh0rBYyQKBgQD3ivFGP2niPVBHGG+cgeYvIHb+FmoklTIBvfEEyIr7evx9KDGe7SDfqmaNZ7UN0FKRCPFFykm2L/E33c+A8rSnNTOwOrqsiPaWxfGEOQBw5iQzsnnWop/9kT707hMQEwnlav9dXD5ZyIZz3vIzMW0ybuN3uE0oFCO0cdOs7tu1TwKBgQDjkVrjNHLpoSgUY3d1/CNy67QuNAR8Qfu1D13uxpIFZnufHO1+ERwM9NvkxawhA/9U5rr6Ez+TwkgHJT/z5GM3o136+VlD6iu0qaaXoJdUOsds3wIvyw1F78timoJJiVxgjxT7Zp9p3cZZhOLktJLIOZN/wRxynXVpS9dSiIg3lQKBgGFB+NvlzF80Qdc9FZUDQIIhmj7oZZmr+LLQguKjPF/kCVHPOfe8KR9XnuVN6sfboqUTQ2BtQxrOqVKO1plOQoYzk/RYjsF9Ko1Ahkyx7Kdu9KhPJimbSYrhxz+KTnkRUeEOcfinZmP2MkVSQgy1Dbcz9DE0ezQU/ZZG5qjaS/5nAoGBANnDCT7rvJ62OT0xZWpAqcdZp6Si4DvrhCrhlphb6fVC+T7sFpMRWk9HrHhBdBJv2dBrrjaJXshNHFHCIm2Hei4OpWr5WqMznTkXMrRb1xOh353d1SDY5E2tRmmHwu8Ng5lescxUim1q7FhTYi9KYD87YVrZ9xfydx0YluaCgh71AoGAJnSPtuwng+5AQD+7uR/vg1NKIyZPwLbkIdnuLFe3hMeD1tI3dTvKgc1bT0A6qRxfv47jDe5TliELJev6Jgcs6UNxYmlR/JedwKpo7AvQS4yJY15H2wcTCQc0lU8pnot46uUwkuVNYu6qBGfIPAefZhyvbLgThAsazJjuq6QiQ28=",
                        "json",
                        "UTF-8",
                        "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAv4FgjWsfvbXEkzs5T+z5r4X9m5Qh8OA0zlZA3T9yeCqlcRRqydMBfRsB4V9aHUH0KCV875mzF7Feh3VoDilcDpGtuKo5l7YRVnGSyQTq0pQjMFYi/wKGFGHAA37Wl2L/AMaGpT6CJncSqcAJssY61qmz/o9lw+hRq6KBfdktl4xm0d5f+uMgCLKqa6bYbFyG7vNZszGJ6yW2n6fFbZ0B4PgPXfrRFVG+OS204bi7sGDba6DuJPPuk8B/gkVoDkmKHNRnLXZi74jyZROlEXKr8JElZqpT6RODkKAmIRCGlQrAadUntgmymguRlN2K+TfSNIigY1FRekb/BudYhlbA5QIDAQAB",
                        "RSA2");
        //统一收单下单并支付页面接口
        // alipay.trade.page.pay
        AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();
        request.setNotifyUrl("");
        request.setReturnUrl("");
        JSONObject bizContent = new JSONObject();
        bizContent.put("out_trade_no", "20210817010101004");//商户订单号
        bizContent.put("total_amount", 0.01);
        bizContent.put("subject", "测试商品123");
        bizContent.put("product_code", "FAST_INSTANT_TRADE_PAY");
        //bizContent.put("time_expire", "2022-08-01 22:00:00");
        //bizContent.put("qr_pay_mode", "3");

        //// 商品明细信息，按需传入
        //JSONArray goodsDetail = new JSONArray();
        //JSONObject goods1 = new JSONObject();
        //goods1.put("goods_id", "goodsNo1");
        //goods1.put("goods_name", "子商品1");
        //goods1.put("quantity", 1);
        //goods1.put("price", 0.01);
        //goodsDetail.add(goods1);
        //bizContent.put("goods_detail", goodsDetail);

        //// 扩展信息，按需传入
        //JSONObject extendParams = new JSONObject();
        //extendParams.put("sys_service_provider_id", "2088511833207846");
        //bizContent.put("extend_params", extendParams);

        request.setBizContent(bizContent.toString());
        AlipayTradePagePayResponse response = alipayClient.pageExecute(request);
        if(response.isSuccess()){
            System.out.println("调用成功");
            System.out.println(response.getBody());//返回页面
        } else {
            System.out.println("调用失败");
        }


    }
}
